package com.sumainfor.wx.system.epc.controller;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.wx.system.epc.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 功能描述:
 *
 * @Auther: zhlu
 * @Date: 2019/6/11 19:48
 * @Description:
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    OrderService OrderService;

    /**
     * 功能描述: 
     * 根据unionid获取当前用户的工单总数（包括强派工单）
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/6/11 19:51
     */
    @PostMapping("/getOrderCount")
    public JsonResult getOrderCount(@RequestBody Map<String,Object> params){
        return OrderService.getOrderCount(params);
    }

    /**
     * 功能描述:
     * 根据用户编号查询我的工单列表
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/6/12 12:08
     */
    @GetMapping("/getMyOrderList")
    public JsonResult getMyOrderList(@RequestParam Map<String,Object> params, Pager pager){
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout= OrderService.getMyOrderListCount(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>> getMyOrderList=OrderService.getMyOrderList(params);
        result=pageUtils.getJsonResult(getMyOrderList, params, cout);
        return result;
    }

    /**
     * 功能描述: 
     * 受理工单池维修工单为我的工单
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/6/14 10:03
     */
    @PostMapping("/AcceptRepairMyOrder")
    public JsonResult AcceptRepairMyOrder(@RequestBody Map<String,Object>params){
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"RepId"})){
            return  JsonResult.error("RepId不能为空！");
        }
        return OrderService.AcceptRepairMyOrder(params);
    }

}
